package com.bdqn.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bdqn.entity.allParams.PmsCommentParam;
import com.bdqn.entity.PmsComment;
import com.bdqn.entity.responseDate.PmsCommentDto;
import com.bdqn.mapper.PmsCommentMapper;
import com.bdqn.service.PmsCommentPicService;
import com.bdqn.service.PmsCommentService;
import com.bdqn.util.PageDto;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 商品评价表 服务实现类
 * </p>
 *
 * @author hunter
 * @since 2022-04-30
 */
@Service
public class PmsCommentServiceImpl extends ServiceImpl<PmsCommentMapper, PmsComment> implements PmsCommentService {
   @Autowired
   private PmsCommentMapper pmsCommentMapper;


    @Override
    public PageDto<PmsComment> pmsCommentDto(PmsCommentParam pmsCommentParam) {
        PageHelper.startPage(pmsCommentParam.getPageNo(),pmsCommentParam.getPageSize());
        List<PmsCommentDto> pmsComments = pmsCommentMapper.pmsComment(pmsCommentParam);
        for (int i = 0; i < pmsComments.size(); i++) {
            PmsCommentDto pmsComment = pmsComments.get(i);
           List<String>pmsCommentPicService=pmsCommentMapper.selectCommentPicById(pmsComment.getCommentId());
            pmsComment.setImgList(pmsCommentPicService);
        }
        PageInfo pageInfo=new PageInfo(pmsComments);
      //不使用pageHelper的分页对象  自己封装与前台对接的分页对象
         PageDto pageDto=new PageDto();
         pageDto.setPageNo(pageInfo.getPageNum());
         pageDto.setPageSize(pageInfo.getPageSize());
         pageDto.setList(pageInfo.getList());
         pageDto.setTotal(pageInfo.getTotal());
         pageDto.setPages(pageInfo.getPages());
         pageDto.setBeginPos(pageInfo.getPageNum());

        return pageDto;
    }


}
